import 'package:dio/dio.dart';
import 'package:enjoy_plus_flutter_7/constants/index.dart';
import 'package:enjoy_plus_flutter_7/utils/RequestDio.dart';
import 'package:image_picker/image_picker.dart';

sendCodeAPI(Map<String, dynamic> params) {
  return requestDio.get(HTTP_PATH.USER_SEND_CODE, params: params);
}

loginAPI(Map<String, dynamic> data) {
  return requestDio.post(HTTP_PATH.USER_LOGIN_CODE, data: data);
}

//请求我的信息的API接口函数
getUserInfoAPI() {
  return requestDio.get(HTTP_PATH.USER_INFO);
}

updateUserInfoAPI(Map<String, dynamic> data) {
  return requestDio.put(HTTP_PATH.USER_INFO, data: data);
}

//请求上传用户头像的API接口函数
uploadAvatarAPI(XFile file) async {
  FormData formData = FormData.fromMap({
    'file': MultipartFile.fromBytes(
      await file.readAsBytes(), // 获取文件二进制数据-u8array
      filename: file.name, // 文件名
      contentType: DioMediaType('image', 'jpg'),
    ),
    'type': 'avatar',
  });

  return requestDio.upload(HTTP_PATH.USER_UPLOAD_AVATAR, data: formData);
}

Future<dynamic> getHouseListAPI() => requestDio.get(HTTP_PATH.HOUSE_LIST);
